window.onload = function () {
  document.querySelector('#register-btn').addEventListener('click', function () {
    let username = document.querySelector("#regist_user").value
    let password = document.querySelector('#pass').value
    let phone = document.querySelector('#phone').value
    let gender = document.querySelector('#gender').value

    let data = {
      phone: phone,
      name: username,
      gender: gender,
      password: password
    }
    resist(data)
  })
  document.querySelector('#have-login').addEventListener('click', function () {
    window.location.href = "./login.html";
  })
}
let resist = async (data) => {
  let res = await ajax({
    type: 'post',
    url: 'http://127.0.0.1:4000/regist/register',
    data: data
  })
  // console.log(res);
  let ress = JSON.parse(res);
  if (ress.code == 200) {
    localStorage.setItem('phone', data.phone);
    alert(ress.message);
    window.location.href = "login.html";
  } else if (ress.code == 201) {
    alert(ress.message)
  }
}